home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Graphical_2101472112008.psc / Classes / c32bppDIB.cls
Text File  |  2007-06-22  |  47KB  |  768 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "c32bppDIB"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ' Credits/Acknowledgements - Thanx goes to:
  17. '   Paul Caton for his class on calling non VB-Friendly DLLs that use _cdecl calling convention
  18. '       Used when calling non VB-friendly zLIB dll versions
  19. '   Alfred Koppold for his PNG, VB-only, decompression routines.
  20. '       Used when zLib & GDI+ not available
  21. '   Carles P.V for his pvResize logic
  22. '       Used when manually scaling images with NearestNeighbor or BiLinear interpolation
  23. '   www.zlib.net for their free zLIB.dll, the standard DLL for compressing/decompressing PNGs
  24. '       Without it, we'd be limited to GDI+ for creating PNGs
  25. '   coders like you that provide constructive criticism to make this class better & more all-inclusive
  26. '       Without your comments, this project probably would have died several versions/updates ago
  27. ' For most current updates/enhancements visit the following:
  28. '   Visit http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=67466&lngWId=1
  29.  
  30. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  31. '                                    O V E R V I E W
  32. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  33. ' About 32bpp pre-multiplied RGB (pARGB) bitmaps, if you are not aware.
  34. '   - These are used specifically for the AlphaBlend API & are GDI+ compatible
  35. '   Advantages:
  36. '       - Images can be per-pixel alpha blended
  37. '       - Opacity can be simultaneously adjusted during rendering
  38. '       - AlphaBlend does both BitBlt & StretchBlt for pARGB images.
  39. '       - Speed: AlphaBlend & GDI+ are pretty quick APIs vs manual blending
  40. '   Disadvantages:
  41. '       - The original RGB values are permanently destroyed during pre-multiplying
  42. '           -- Premultiplied formula: preMultipliedRed=(OriginalRed * Alpha) \ 255
  43. '           -- There is no way to convert pARGB back to non-premultiplied RGB values
  44. '              The formula would be: reconstructedRed=(preMultipliedRed * 255) \ Alpha.
  45. '               but because of integer division when pre-multiplying, the result is only
  46. '               close and if this should be premultiplied again & converted again, the
  47. '               alphas can get more transparent with every iteration.
  48. '               Fully opaque pixels & fully transparent pixels are not affected.
  49. '           ** Note: When images are converted to PNG formats, removal of
  50. '              premultiplication is performed to meet PNG specs.
  51. '       - Displaying a pre-multiplied bitmap without AlphaBlend will not result in
  52. '           the image being displayed as expected.
  53. '       - Not ideal for saving due to its size: SizeOf= W x H x 4
  54. '           -- better to save source image instead or compress the DIB bytes using favorite compression utility
  55. '           -- with GDI+ or zLib, image can be converted to PNG for storage
  56. '       - AlphaBlend (msimg32.dll) is not included/compatible with Win95, NT4 and lower
  57. '       - AlphaBlend on Win9x systems can be buggy, especially when rendering to DIBs vs DDBs
  58. ' Note that GDI+ is standard on WinXP+, and can be used on Win98,ME,2K, & on NT4 if SP6 is installed
  59.  
  60. ' ----------------------------------------------
  61. ' About Win95, Win98, NT3.5, NT4 & WinME support
  62. ' ----------------------------------------------
  63. ' The routines will not honor AlphaBlend if it exists on those systems. Win98's version,
  64. ' for example, has several bugs that can crash the application when AlphaBlending to DIBs.
  65. ' NT4, NT3.5 & Win95 do not come with AlphaBlend and I do not have WinME to test with.
  66. ' Therefore, to support these systems, the Render routine will alphablend manually
  67. ' regardless if the AlhpaBlend API (msimg32.dll) exists on the system or not.
  68.  
  69. ' Table of methods used for rendering dependent upon class settings and O/S
  70. ' ----------------------------------------------------------------------------------
  71. ' Win2K or Better?  GDI+ Available?  HighQualityInterpolation?  Method of Rendering
  72. '       Yes              Yes                No / Yes            AlphaBlend / GDI+
  73. '       No               Yes                No / Yes            GDI+ / GDI+
  74. '       Yes              No                 No / Yes            AlphaBlend / Manually
  75. '       No               No                 No / Yes            Manually / Manually
  76. ' Note that AlphaBlend does not support mirroring nor rotation nor high quality interpolation,
  77. ' so if these are applied when rendering, then class will use GDI+ if available,
  78. ' otherwise, manually rendered. By default, the class will initialize with
  79. ' HighQualityInterpolation=True if GDI+ is available.
  80. ' ----------------------------------------------------------------------------------
  81.  
  82. ' Class Purpose:
  83. ' This class holds the 32bpp image. It also marshals any new image thru
  84. ' the battery of parsers to determine best method for converting the image
  85. ' to a 32bpp alpha-compatible image. It handles rendering, rotating, scaling,
  86. ' mirroring of DIBs using manual processes, AlphaBlend, and/or GDI+.
  87. ' What about DirectX?  Hmmmm...
  88.  
  89. ' The parser order is very important for fastest/best results...
  90. ' cPNGparser :: will convert PNG, all bit depths; aborts quickly if not PNG
  91. ' cGIFparser :: will convert non-transparent/transparent GIFs; aborts quickly
  92. ' cICOpraser :: will convert XP-Alpha, paletted, true color, & Vista PNG icons
  93. '               -- can also convert most non-animated cursors
  94. ' cBMPparser :: will convert bitmaps, wmf/emf & jpgs
  95.  
  96. ' The parsers are efficient. Most image formats have a magic number that give
  97. '   a hint to what type of image the file/stream is. However, checks need to
  98. '   be employed because non-image files could feasibly have those same magic
  99. '   numbers. If the image is determined not to be one the parser is designed
  100. '   to handle, the parser rejects it and the next parser takes over.  The
  101. '   icon parser is slightly different because PNG files can be included into
  102. '   a Vista ico file. When this occurs, the icon parser will pass off the
  103. '   PNG format to the PNG parser automatically.
  104. ' And last but not least, the parsers have no advanced knowledge of the image
  105. ' format; as far as they are concerned, anything passed is just a byte array
  106.  
  107. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  108. '                                       CHANGE HISTORY
  109. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  110. ' Accompanying FAQ.rtf is updated with every change
  111. ' 3 Mar 07
  112. '   - Major bug realized.
  113. '       Thru trial and error, I have found that calling iparseIsArrayEmpty can generate
  114. '       "Expression Too Complex" errors in the routine that called that function. However, I
  115. '       cannot determine why and when this happens. It is an inconsistent error. The same O/S
  116. '       different PCs may or may not generate that error, but the iparseIsArrayEmpty is
  117. '       definitely involved. Therefore, I have rewritten that function and modified every
  118. '       line of code that calls that function.
  119. ' 2 Mar 07:
  120. '   - Bugs recognized & fixed
  121. '       - Using some zLib versions, PNG files may be much larger than expected. Fixed;
  122. '           -- the variable passed to zLib was not being updated with compressed size; ByVal,ByRef issue
  123. '           -- iparseValidateZLIB modified; could incorrectly identify calling convention for latest zLIB VB-version
  124. '           -- special thanx to Robert Rayment for helping troubleshooting this -- sorry for crashing your pc ;)
  125. '       - DIBs converted to palettized PNGs, without alpha, did not write the palette; fixed
  126. '       - WinME only. Manually rendering to WinME produced artifacts from the alpha channel; fixed
  127. '           -- modified Win9xBlend to use GetDIBits & SetDIBitsToDevice vs BitBlt; actually improved speed
  128. '           -- special thanx to Herman CK for helping troubleshoot this; I don't have WinME
  129. '       - This class' Initialize event corrected to positively identify Win2K and above.
  130. '   - Added 5 more grayscale options: RedMask, GreenMask, BlueMask, RedGreenMask, BlueGreenMask
  131. '       - Changed NTSC/PAL grayscale formula to be the default. See MakeGrayScale
  132. '   - Modified GetDIBbits to allow retrieval of non-premultiplied pixels
  133. '   - Modified SetDIBbits to accept either premultiplied or non-premultiplied pixels
  134. ' 27 Feb 07: by request
  135. '   - Added 3 supporting functions to extract DIB bytes into a passed array
  136. '       - GetDIBbits & SetDIBbits gets/sets DIB pixels
  137. '           -- parameters to return bytes in various formats/structures combinations
  138. '       - GetAlphaMask gets the DIB alpha values as an 8 byte/256 color, grayscale, array.
  139. ' 20 Feb 07:
  140. '   - PNGparser conversion routines overhauled for speed, minor error found & fixed
  141. '       -- PNGparser.InitializePalette did not correctly identify transparency index for Grayscale with simple transparency
  142. '   - PNGwriter.FormatCaption & FormatText recognized non-spec text but did not prevent it from being written to PNG
  143. '   - Modified PNGwriter to use zLIB compress2 function when available
  144. '   - Error on my part, last post had debugging code using zLibVB.dll vs zLib.dll
  145. '       -- no serious harm but versions prior to this update probably will not be able to use zlib.net's zLib.DLL
  146. ' 18 Feb 07:
  147. '   - Bugs recognized & fixed
  148. '       -- cPNGwriter.OptimizeTrueColor could error when converting to 24bpp images
  149. '       -- cPNGwriter.OptimizeTrueColor was not writing the single transparency color for 24bpp converted images
  150. '       -- cPNGwriter.Write_tRNS was not always writing the tranpsarency color either
  151. '       -- PngPropertySet was not honoring the user-selected filterMethod property
  152. ' 16 Feb 07:
  153. '   - More PNG support....(First non-GDI+ PNG writer in VB open source? Maybe.)
  154. '       -- Added cPNGwriter class. Can create PNGs using zLIB.dll versions. See class for more
  155. '       -- Added cCDECL class. Allows calling zLIB.dll when zLIB is not VB-friendly
  156. '           -- added modParsers.iparseValidateZLIB to determine if zLIB is available & if VB-friendly
  157. '           -- required adding some custom zLIB calls to end of cPngWriter & cPngParser classes
  158. '       -- added PngPropertySet to allow PNG creation options not possible w/GDI+. Must have zLIB available
  159. '       -- added PngPropertyGet to retrieve settings. Over a dozen options
  160. '       -- added isZlibEnabled property to inform you if zLIB can be used or not
  161. '       -- Modified SaveToStream_PNG & SaveToFile_PNG to use zLIB if GDI+ is not available,
  162. '               but zLIB is or vice versa. zLIB is prefered when pngPropertySet is called
  163. '       -- Zlib is 100% free and is available directly from source: www.zlib.net
  164. ' 11 Feb 07:
  165. '   - Logic error. When a DIB is first initialized, the Alpha property is False.
  166. '       This should have been Alpha=True. Note that if you are creating blank DIBs and rendering other
  167. '       DIBs to the blank one, you should change the blank DIB's alpha and image format properties as
  168. '       appropriate, dependent upon what you are rendering to that DIB. The Alpha property is used in
  169. '       other routines and must be accurate, but the ImageType property is not used
  170. '   - Added imgError to the ImageType property enumeration. This can assist when self-rendering
  171. '       DIBs. If ImageType=imgError then Handle=0& and no DIB has been loaded into the class.
  172. ' 10 Feb 07:
  173. '   - Added LoadPicture_FromOrignalFormat routine which will recreate the DIB from the bytes
  174. '       cached during a call to LoadPicture_File or LoadPicture_Stream
  175. '   - Added TrimImage routine which will remove excess transparency from an image
  176. '       If a 256x256 image has 20x20 transparency border around it, the image will be reduced to 216x216
  177. '   - When calling Resize, class would not save original image bytes if they existed; now it does
  178. '   - Minor tweaks in rotation routines. Routines no longer overwrite class' Interpolation setting
  179. '   - Logic error fixed: GDI+ when rendering mirrored & rotated used incorred DC X,Y coordinates
  180. ' 4 Feb 07:
  181. '   - Added SaveToFile_PNG & SaveToStream_PNG as main class options, but only supported if isGDIplusEnabled = True
  182. '   - Complete revamp of mirroring routines.
  183. '       -- Added MirrorDIB routine that mirrors an image as needed & mirrored bytes are later rotated, scaled, rendered
  184. '       -- Previous version attempted to calculate mirroring offsets when scaling, rotating, rendering -- failed
  185. '       -- Following routines modified: pvResize, CopyImageTo, Resize, RotateAtTopLeft
  186. '   - Logic error fixed: pvResize would clip wrong end of image when image is rendered past vertical bounds of DC.
  187. '   - Modified startup to always set HighQualityInterpolation if GDI+ is available.
  188. ' 1 Feb 07: By request...
  189. '   - Added mirroring support to following routines. Passing a negative destination width and/or height causes mirroring
  190. '       - pvResize, Win9xBlend, CopyImageTo, Resize, RotateAtCenterPoint, RotateAtTopLeft & cGDIPlus.RenderGDIplus
  191. '       - The msimg32.dll AlphaBlend API cannot perform mirroring. Therefore...
  192. '       - Whenever mirroring is in effect and GDI+ can't be used, mirroring will be done manually
  193. '       - GDI+, if available, will only perfrorm the mirroring if also rotating or if HighQualityInterpolation=True
  194. '   - Found another minor bug. Broke GDI+ ability to Global blend while rotating. Fixed.
  195. ' 31 Jan 07:
  196. '   - Fixed logic error when rotating negative angles via GDI+ (cGDIPlus.RenderGDIplus routine)
  197. '   - Fixed logic error when manually resizing using BiLinear method (pvResize routine)
  198. '       - routines were combining current pixel with one above, not below as required
  199. '   - Fixed rotation routines (non-GDI+); now rotation while non-proportional scaling compatible
  200. '   - Renamed cPNGParser.SaveTo routine to cGDIPlus.SaveToPNG. See Change 4Jan07 below for more
  201. ' 30 Jan 07:
  202. '   - Added rotation options. See RotateAtCenterPoint & RotateAtTopLeft
  203. '       - The two routines are identical except for how the destination X,Y coords are determined
  204. '   - Added isGDIplusEnabled property to inform you whether or not GDI+ can be used on the system
  205. '   - Added HighQualityInterpolation property to produce better renderings
  206. '       - When set to True & GDI+ is available, any rendering is done by GDI+
  207. '       - When set to True and GDI+ is not available, manual interpolation is done when scaling/rotating
  208. '       - Property can be set to False manually to prevent GDI+ usage
  209. '   - Added MakeGrayScale routine. Irreversible pixel modifications
  210. '       - 3 different grayscale formulas are provided
  211. '   - Relocated all GDI+ function calls and related code into a new class: cGDIPlus
  212. '   - Relocated cPNGparser.ValidateDLL to modParsers as iparseValidateDLL
  213. ' 25 Jan 07:
  214. '   - Modified Win9xBlend routine. Did not exactly replicate AlphaBlend when stretching; fixed I believe
  215. '       -- Added extra checks in Win9xBlend & pvResize when alphablending on Win9x systems.
  216. '       -- Prevents user from supplying invalid values that could cause routines to read past allocated memory
  217. '       -- Properly handles negative destination DC offsets
  218. '   - Changed iswin95Alpha property to isAlphaBlendFriendly to indicate whether or not AlphaBlend will be used
  219. ' 24 Jan 07:
  220. '   - Now compatible with all O/S. Added Win95/NT4 support to the following routines:
  221. '       CopyImageTo, Resize, Render
  222. '       -- Added Win9xBlend & heavily modified then added Carles P.V.'s pvResize routine
  223. '   - Bug found. cPNGparser.vbDecompress, under NT4, was causing crashes when trying to
  224. '       resize a passed byte array. Fixed. Array is sized before it is passed to that routine
  225. '   - Bug found. The iparseCreateShapedRegion routine was creating shaped regions bottom up
  226. '       and this crashed on NT4. Fixed so regions are created top down always
  227. '   - Bug found. In Win98 & possibly other O/S. When VB creates a 24bpp stdPicture as used
  228. '       in cBMPparser, the stdPicture.Render method can write into the alpha channel of the
  229. '       destination 32bpp DIB; 24bpp has no alpha channel. Routine tweaked to handle that.
  230. ' 17 Jan 07:
  231. '   - Added CreateCheckerBoard method. This method will create a checkerboard pattern
  232. '       as the DIB image. It will also set the ImageType property to imgCheckerBoard
  233. '       so you know whether or not the image is class checkerboard or not.
  234. '       This can be useful when the DIB should be displayed, but has no image to display.
  235. '       The flag can be used to determine saving the image. If imgCheckerboard then noSave
  236. '   - Added Resize method to permanently resize the image within the DIB
  237. '   - Added optional resizing parameters to CopyImageTo routine
  238. '   - Tweaked cBMPparser & cGIFparser to always modify alpha bytes regardless of transparency
  239. '       -- Previously, when image had no transparency, the alpha bytes were not touched, rather
  240. '          the class tracked this information via its Alpha property. But if you wanted to pass
  241. '          the DIB to some other routine in your project and process/render it, the unmodified
  242. '          alpha bytes could prove to fool those processes/routines
  243. '   - Tweaked Render method to fully expose all of AlphaBlend's parameters
  244. '   - LoadPicture_StdPicture could not process WMFs, fixed
  245. '   - LoadDIBinDC fixed - could fail if multiple calls made passing a True parameter
  246. '   - Error in LoadPictureEx prevented saving image bytes when PNG file was loaded, fixed
  247. ' 5 Jan 07:
  248. '   - Added SaveFormat parameter to LoadPicture_File & LoadPicture_Stream
  249. '       -- option has class cache the original bytes of the image if loaded
  250. '       -- the 32bpp DIB will always be larger than the source bytes and for
  251. '           usercontrols, saving the original bytes takes less space than
  252. '           saving the DIB bytes.
  253. '   - Added GetOrginalFormat to retrieve bytes when SaveFormat was passed as True
  254. '   - Added SetOriginalFormat used when copying one DIB class to another
  255. ' 4 Jan 07:
  256. '   - Added LoadPicture_ByHandle, LoadPicture_StdPicture, ScaleImage & CopyImageTo
  257. '   - Added cGDIPlus.SaveToPNG (testing). Requires GDI+ or zLIB but will save 32bpp to PNG file or stream
  258. '       -- not accessible, right now, from c32bppDIB. Must create cGDIPlus class to use it.
  259. '   - Modified cICOparser's GetBestMatch algorithm
  260. '   - Added imgPNGicon as an image type to distinguish PNG in Vista Icon vs standard .PNG file
  261. '   - Bug found: removing overlays in cGIFparser.ConvertGIFto32bpp; forgot ByVal VarPtrArray(...)
  262. '       which could cause crash when compiled. Fixed & double checked everywhere else too
  263. ' 1 Jan 07:
  264. '   - Added SaveToFile & SaveToStream methods
  265. '   - cBMPparser could possibly try to query unauthorized memory; fixed
  266. '   - Methodology changed a bit when parsers return results. If image is definitely one
  267. '       that the parser is responsible for & the image is invalid, the parser will return
  268. '       True to prevent other parsers from handling the image. The c32bppDIB.Handle is used
  269. '       to determine true success or failure.
  270. '       -- cGIFparser when recognizing improperly formatted GIF would allow image to continue to
  271. '           other parsers which then may cause those parsers to lock up.
  272. ' 26 Dec 06: First version
  273. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  274.  
  275.  
  276. ' No APIs are declared public. This is to prevent possibly, differently
  277. ' declared APIs, or different versions of the same API, from conflciting
  278. ' with any APIs you declared in your project. Same rule for UDTs.
  279. ' Note: I did take liberties, changing parameter types, in several APIs throughout
  280.  
  281. ' Used to determine operating system
  282. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As Any) As Long
  283. Private Const VER_PLATFORM_WIN32_WINDOWS As Long = &H1&
  284. Private Type OSVERSIONINFOEX
  285.    dwOSVersionInfoSize As Long
  286.    dwMajorVersion As Long
  287.    dwMinorVersion As Long
  288.    dwBuildNumber As Long
  289.    dwPlatformId As Long
  290.    szCSDVersion As String * 128 ' up to here is OSVERSIONINFO vs EX
  291.    wServicePackMajor As Integer ' 8 bytes larger than OSVERSIONINFO
  292.    wServicePackMinor As Integer
  293.    wSuiteMask As Integer
  294.    wProductType As Byte
  295.    wReserved As Byte
  296. End Type
  297.  
  298. ' APIs used to manage the 32bpp DIB
  299. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  300. Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
  301. Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
  302. Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  303. Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
  304. Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
  305. Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
  306. Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hdc As Long, ByRef pBitmapInfo As Any, ByVal un As Long, ByRef Pointer As Long, ByVal Handle As Long, ByVal dw As Long) As Long
  307. Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdcDest As Long, ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, ByVal nWidthDest As Long, ByVal nHeightDest As Long, ByVal hdcSrc As Long, ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, ByVal lBlendFunction As Long) As Long
  308. Private Declare Function SetStretchBltMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
  309. Private Declare Function GetObjectType Lib "gdi32.dll" (ByVal hgdiobj As Long) As Long
  310. Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
  311. Private Declare Function GetIconInfo Lib "user32.dll" (ByVal hIcon As Long, ByRef piconinfo As ICONINFO) As Long
  312. Private Declare Function SetDIBitsToDevice Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dX As Long, ByVal dY As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, ByRef Bits As Any, ByRef BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
  313. Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, ByRef lpBits As Any, ByRef lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
  314. Private Const STRETCH_HALFTONE As Long = &H4&
  315. Private Const OBJ_BITMAP As Long = &H7&
  316. Private Const OBJ_METAFILE As Long = &H9&
  317. Private Const OBJ_ENHMETAFILE As Long = &HD&
  318.  
  319. ' APIs used to create files
  320. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  321. Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
  322. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  323. Private Const INVALID_HANDLE_VALUE = -1&
  324. Private Const CREATE_ALWAYS = &H2&
  325. Private Const GENERIC_READ = &H80000000
  326. Private Const GENERIC_WRITE = &H40000000
  327. Private Const FILE_ATTRIBUTE_NORMAL = &H80&
  328.  
  329. ' used to create the checkerboard pattern on demand
  330. Private Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
  331. Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
  332. Private Declare Function OffsetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
  333. Private Type RECT
  334.     Left As Long
  335.     Top As Long
  336.     Right As Long
  337.     Bottom As Long
  338. End Type
  339.  
  340. ' used when saving an image or part of the image
  341. Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
  342. Private Type SafeArrayBound
  343.     cElements As Long
  344.     lLbound As Long
  345. End Type
  346. Private Type SafeArray
  347.     cDims As Integer
  348.     fFeatures As Integer
  349.     cbElements As Long
  350.     cLocks As Long
  351.     pvData As Long
  352.     rgSABound(0 To 1) As SafeArrayBound ' reusable UDT for 1 & 2 dim arrays
  353. End Type
  354.  
  355. Private Type ICONINFO
  356.     fIcon As Long
  357.     xHotspot As Long
  358.     yHotspot As Long
  359.     hbmMask As Long
  360.     hbmColor As Long
  361. End Type
  362. Private Type BITMAPINFOHEADER
  363.     biSize As Long
  364.     biWidth As Long
  365.     biHeight As Long
  366.     biPlanes As Integer
  367.     biBitCount As Integer
  368.     biCompression As Long
  369.     biSizeImage As Long
  370.     biXPelsPerMeter As Long
  371.     biYPelsPerMeter As Long
  372.     biClrUsed As Long
  373.     biClrImportant As Long
  374. End Type
  375. Private Type BITMAPINFO
  376.     bmiHeader As BITMAPINFOHEADER
  377.     bmiPalette As Long
  378. End Type
  379.  
  380. '// Added by Bryan Utley
  381.  
  382. Private Type RGBQUAD
  383.     B           As Byte
  384.     G           As Byte
  385.     R           As Byte
  386.     A           As Byte
  387. End Type
  388.  
  389. Private Type SAFEARRAY2D
  390.     cDims       As Integer
  391.     fFeatures   As Integer
  392.     cbElements  As Long
  393.     cLocks      As Long
  394.     pvData      As Long
  395.     Bounds(1)   As SafeArrayBound
  396. End Type
  397.  
  398. '// --------------------------
  399.  
  400.  
  401. Private Const AC_SRC_OVER = &H0&
  402. Private Const AC_SRC_ALPHA = &H1&
  403.  
  404. Public Enum eImageFormat    ' source image format
  405.     imgError = -1  ' no DIB has been initialized
  406.     imgNone = 0    ' no image loaded
  407.     imgBitmap = 1  ' standard bitmap or jpg
  408.     imgIcon = 3    ' standard icon
  409.     imgWMF = 2     ' windows meta file
  410.     imgEMF = 4     ' enhanced WMF
  411.     imgCursor = 5  ' standard cursor
  412.     imgBmpARGB = 6  ' 32bpp bitmap where RGB is not pre-multiplied
  413.     imgBmpPARGB = 7 ' 32bpp bitmap where RGB is pre-multiplied
  414.     imgIconARGB = 8 ' XP-type icon; 32bpp ARGB
  415.     imgGIF = 9      ' gif; if class.Alpha=True, then transparent GIF
  416.     imgPNG = 10     ' PNG image
  417.     imgPNGicon = 11 ' PNG in icon file (Vista)
  418.     imgCursorARGB = 12 ' alpha blended cursors? do they exist yet?
  419.     imgCheckerBoard = 64 ' image is displaying own checkerboard pattern; no true image
  420. End Enum
  421.  
  422. Public Enum ePngProperties ' following are recognized "Captions" within a PNG file
  423.     txtTitle = 1           ' See cPNGwriter.SetPngProperty for more information
  424.     txtAuthor = 2
  425.     txtDescription = 4
  426.     txtCopyright = 8
  427.     txtCreationTime = 16
  428.     txtSoftware = 32
  429.     txtDisclaimer = 64
  430.     txtWarning = 128
  431.     txtSource = 256
  432.     txtComment = 512
  433.     ' special properties
  434.     txtLargeBlockText = 1024 ' this is free-form text can be of any length & contain most any characters
  435.     dateTimeModified = 2048  ' date/time of the last image modification (not the time of initial image creation)
  436.     colorDefaultBkg = 4096   ' default background color to use if PNG viewer does not do transparency
  437.     filterType = 8192        ' one of the eFilterMethods values
  438.     ClearAllProperties = -1  ' resets all PNG properties
  439. End Enum
  440.  
  441. Public Enum eTrimOptions    ' see TrimImage method
  442.     trimAll = 0             ' can be combined using OR
  443.     trimLeft = 1
  444.     trimTop = 2
  445.     trimRight = 4
  446.     trimBottom = 8
  447. End Enum
  448.  
  449. Public Enum eScaleOptions   ' See ScaleImage method
  450.     scaleToSize = 0         ' [Default] will always scale
  451.     scaleDownAsNeeded = 1   ' will only scale down if image won't fit
  452.     ScaleStretch = 2        ' wll always stretch/distort
  453. End Enum
  454.  
  455. Public Enum eGrayScaleFormulas
  456.     gsclNTSCPAL = 0     ' R=R*.299, G=G*.587, B=B*.114 - Default
  457.     gsclCCIR709 = 1     ' R=R*.213, G=G*.715, B=B*.072
  458.     gsclSimpleAvg = 2   ' R,G, and B = (R+G+B)/3
  459.     gsclRedMask = 3     ' uses only the Red sample value: RGB = Red / 3
  460.     gsclGreenMask = 4   ' uses only the Green sample value: RGB = Green / 3
  461.     gsclBlueMask = 5    ' uses only the Blue sample value: RGB = Blue / 3
  462.     gsclRedGreenMask = 6 ' uses Red & Green sample value: RGB = (Red+Green) / 2
  463.     gsclBlueGreenMask = 7 ' uses Blue & Green sample value: RGB = (Blue+Green) / 2
  464. End Enum
  465.  
  466. Public Enum eFilterMethods
  467.     filterDefault = 0     ' paletted PNGs will use filterNone while others will use filterPaeth
  468.     filterNone = 1        ' no byte preparation used; else preps bytes using one of the following
  469.     filterAdjLeft = 2     ' see cPNGwriter.EncodeFilter_Sub
  470.     filterAdjTop = 3      ' see cPNGwriter.EncodeFilter_Up
  471.     filterAdjAvg = 4      ' see cPNGwriter.EncodeFilter_Avg
  472.     filterPaeth = 5       ' see cPNGwriter.EncodeFilter_Paeth
  473.     filterAdaptive = 6    ' this is a best guess of the above 4 (can be different for each DIB scanline)
  474. End Enum
  475.  
  476. Private m_PNGprops As cPNGwriter    ' used for more advanced PNG creation options
  477. Private m_StretchQuality As Boolean ' if true will use BiLinear or better interpolation
  478. Private m_Handle As Long        ' handle to 32bpp DIB
  479. Private m_Pointer As Long       ' pointer to DIB bits
  480. Private m_Height As Long        ' height of DIB
  481. Private m_Width As Long         ' width of DIB
  482. Private m_hDC As Long           ' DC if self-managing one
  483. Private m_prevObj As Long       ' object deselected from DC when needed
  484. Private m_osCAP As Long         ' 1=Can use AlphaBlend (Win2K+), 2=Can use GDI+ (Win98+), 4=Can use zLib. See Class_Initialize
  485. Private m_Format As eImageFormat ' type of source image
  486. Private m_ManageDC As Boolean   ' does class manage its own DC
  487. Private m_AlphaImage As Boolean ' does the DIB contain alpha/transparency
  488. Private m_ImageByteCache() As Byte  ' should you want the DIB class to cache original bytes
  489. ' ^^ N/A if image is loaded by handle, stdPicture, or resource
  490.  
  491. Public Function LoadPicture_File(ByVal FileName As String, _
  492.                                 Optional ByVal iconCx As Long, _
  493.                                 Optional ByVal iconCy As Long, _
  494.                                 Optional ByVal SaveFormat As Boolean) As Boolean
  495.  
  496.     ' PURPOSE: Convert passed image file into a 32bpp image
  497.     
  498.     ' Parameters.
  499.     ' FileName :: full path of file. Validation occurs before we continue
  500.     ' iconCx :: desired width of icon if file is an icon file. Default is 32x32
  501.     ' iconCy :: desired height of icon if file is an icon file. Default is 32x32
  502.     ' SaveFormat :: if true, then the image will be cached as a byte array only
  503.     '   if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
  504.     
  505.     ' Why would you want to save the bytes? If this is being used in a usercontrol,
  506.     ' saving the bytes will almost always be less size than saving the 32bit DIB.
  507.     ' Additionally, these classes have the ability to get different sizes from
  508.     ' the original source (i.e., WMF, icon, cursors) if available, but if the
  509.     ' 32bit DIB is saved, it is a constant size. The potential of different sizes
  510.     ' could allow better resizing of the image vs stretching the DIB.
  511.  
  512.     On Error Resume Next
  513.     If Not iparseFileExists(FileName) Then Exit Function
  514.     If FileLen(FileName) < 57 Then Exit Function
  515.     ' no image file/stream can be less than 57 bytes and still be an image
  516.     If Err Then
  517.         Err.Clearam can be leld change tl       :nt .
  518. '  pIf Err Then
  519.         Er'Left = 2     s Longrr Then
  520.         Er'LeftimgIconARGbFeits Alpha p the 32bit DIB.
  521.     ' AdditDIB.
  522. x    ' see cPNGwriter.EncodeFilter_Subnd
  523. End Tbmst DIB.ditDIB.
  524. xIB is gCheckerBoardVal Hahn occurs bec               Optional ByVal ic(ginalFo On Error Resume Next
  525. e: RGB = Red /  ipacssss passed i           ;cB;usss passed i rorno e 3
  526.     gsclum Resume N24bpp <lter_Subn)ize,  As LoinalFormsume Next
  527. e: RGB = Red /  ipacsssneileLCl
  528.     biHeightPByVal iconvate m_ImageByteCache() As Byte  ' should you waneft = 2   shdese m_ImageByteCache()e()e()e()e()e()i shdese m_ImageBiy As8  imgf:d allow btys modify alpss.Alpha=True,  gsclBlueGr' uses only thD m_prevObj AO combireen) /xdifmodify alpsico th is use 3
  529.    - Tweaked D
  530.  
  531. ' AAs Boolean img32.dll" (ByVal hdcDest As Long, ByVal n ' 
  532.     filterAdjLeft = 2   ked D Long, sizes:imodify alps3
  533.     gsclBlueMaimage
  534. Prigperty. Be
  535.     ' 32bit DIB is savptionn 'ser32.lBlueMaimage
  536. nAoaleImage & CoCRGB  Declare FnalF youeBytm atTrallowileExists(FileName) Then Exn Lontbubllowi Lontbubfv = = = = = = = = = = = = = = = = = = chas classss paToPN:As Saosele =  p+A Long, _
  537.      l have found  ' wn checkerbo = 1        '                )    ' As eImt   ve found  ' wn checkerbo = 1        ' er
  538.     cbi As Long
  539. irterMethods values
  540.  ' high q   ' high q   ' ay
  541.    bmiHeader As BITMAPINFOHEADER
  542.     bmiPalette As Long
  543. End Type
  544.  
  545. '// Added by Bryan Utley
  546.  
  547. Private Type RGBQUAD
  548.     B           As Byte
  549.     G           As Byte
  550.  O.+arency, s Bytespate
  551.     G  uBq         AEnd Enum
  552.  
  553. Pfy alpsype
  554. Privnum
  555. yte
  556.   , ' wn) if available, but i   Gtine thaethods values
  557.  
  558.   , ' wn) if availabt As So On Error Reeass_Initi bettim) if availathaethod= =   &(if avaicy
  559. '-pormat to retrin3)l iconCatTrallowileExte Type RECT
  560.   =   lpsyavai havs.RGB = Bmls
  561.     ' could akedNBr_Subn)ize,  As(           ) t to retrinaI2Br_        ) t to retrinaI2Br_        ) t toon occe focted from DC when need     ClAGchas On Error Resume Next
  562.    iNG fiuata Astspate
  563.     G  u.bH
  564.     If = Bmls
  565.     ' could akeC when need  ' cou
  566. Private Type = 6 ' uses Red & Green saSses have the ability to get different sizes fr& SaveToFile_PC7   ' Asal wUsaconCy As Long, _
  567.   m-- Addetiovcw Any) A3rL<7   'wtiom)ong
  568.   Vrocw Als
  569.   ssng
  570. Priiiiiiiiiiii'       -- 'OkedNBr_Subn)ize,  As(     n checkerbokeckerbokeckerboxwn cui'  ility oaen neeTcd & s    ' iconCy :: desired height of icon if file is ard = 64 ' image is displayingd
  571. End file is ard = = =  1 & 2 dim arwill ods valuess ard = erBoardVal Hahn ocyonCy :oalize
  572. Private m_Format  Booleaal Hom Hom Hom Ho dFormanCy :oalize
  573. PQUAD
  574.    al Hahn ocyonCy_ause crash wan Lontsfs
  575.    , ByVal Scan As Longm= = = = =+,' wn&x.dering is doneI erBoaNsee cPNhe asHahn ocyonCyessSize As Long
  576.     biWidth As Long
  577. er wimanCy :oA=+,' wn&x.dering ' specit.iparseValidaer e_PC7renderings
  578. '       - When set to True & GDI+ is available, any rendering is dongt for lN=pNumberOfByLonge meileName) Thny rendering is dongt foroloaded. Call As &ofc  ' Se[ldge meilllllllllllllllll nHeightSrc As Long, ByVaaon FillRetermined not to be one tg is donH80000000
  579. Private Const GENERRtlMoveDirectX?  Hmmmnfo As lllllll n Th,ugging co-y involved. Therefore, xtDesct to End EnumSd; ) t t:e Ho dFmultiplied
  580.     imgIconARB imYd. CaBr_Subn)ize,  Aor  On Error ReeoadPicr  On   On   Onis ar Then
  581.    5    On   Onis ar ThOiirectX?  Hmmmnfo As lectX?  Hmmmnnfo As lecCed. TheAs lectX?  Hmmmnk up.
  582. ' 26 Dec 06: Fin   Onis ar Thn oD pup.
  583. 'te revamp of m. bn)ize,  Aor  On EEEEEEEEEEEEEEEE Se[ldo Th,eEEELong
  584. End Type
  585. Private Type BITMter As Long co todnity oaen do s5om Hom HightSrc As L
  586. End Tyyyyym HightSr"Captions" within LE As Long = &HeOn   OnisalFo On Error Resume Ne' B=B*e of aht As LConfe valsnt to<SbmiPand Tyardate m_Format  Booleaal Hom Hom Hom Ho dF aon EEEE  EEEE ader Ass Long co todnir Ass L"i'   - Added ophould you wanefta_FormS[ard pattern
  587. ' _        ).EncodeFilter_Avg
  588. Sd; ) t t:e Ho dFmultiplied
  589.     imgIconARB i,----r=Esrd; )Fmulties
  590.  ' high  Then
  591.    5 lties
  592.  ' hign DeleteObjnd Tyaling/rotating
  593. '       - Property can be set to False manually n imabjnd Tyali manuallnt to< it, the imagr Resgse manually n ima, the image ultiplie= = =nuaanuallyAny) A3rL<7   'wtmanuallnt t of eAs lectX?  Hmm Thue APINFOHEhAoadDIBinDC fixed -uaanuallyAny)   'wtmanualfC fi, Thum?  Hmms Lops oEps oEps oEps oEps oEps o)Dile is WN24bp lelBlsN24bp s(    oX?  Hmmmnfo As lllllll n Th,ugging co-y involved. Tbj As LongT.Tbmst DIB.ditDIB.
  594. xIB is gCheckerBoardVal Hahn occurs bec               Optional ByVal ic(ginalFo On Error Resume Next
  595. e: RGB = Red /  ipacssss passed i         iiiiB As LongT.Tbss paToPN:As Sssss pasge & CoCRGBolved. Tbja'sge nd(0 To 1) As Srwpacsr_AvgrhpimgIconARB o(er As=&1rN value: RGB 
  596. Pxed -O 'OkedNBr_Sude
  597.     G  u_Sudety ong, o  biHeide
  598.     G  u_Sudety ong, o
  599. 2alized.d I belbo 32bpp DIB
  600. Privat u_Su(ginalFlbo 3.xAL = 0   aectHo dFmultipliStHo dieT1 Iconlbo 3dDIetObrency color eitn set toinalFlbo 3re F  shouldptionallllll within LE A F  stbrency colGchas On ErrobckerBLE Aen 5E A F  stO Bytespot As Long m-- B;usss passed i    )  i    spotr/ L
  601. End    o / ing, then clm caB o(er Asclm caB o(erill ret   o / ing, then cspot Asrhpi, thenus
  602. E               ' er
  603.   r&(ifxe57 Thene
  604.     G  u.bH
  605.     If =    ' er
  606.   If =    todniu
  607. Privatk
  608. '       resize a ima.Eps oEps o)DilIconARB o(er As=&1rN value: RGB 
  609. Pxed -O 'OkedNBr_Sude
  610.     G  u_Sudety ong, o  biHeide
  611.     G  u_Sudety ong, o
  612. 2alized.d I belbo 32bpp DIB
  613. Privat u_Su(ginalFlbo 3.xAL = 0   aeaectHo False mCoCRGoutthe imrAs Lon+arency, s Bytespate
  614.     G  uBq d:p where 0   aectHo dtHo dieT1 Icoety ve found  ' wn checkerbo = Ailter_Up
  615.     filtee&  resize a i is aver_Up
  616.     filtee&rbo = A /  ip'thin a PNG f2ef ldety ong, o
  617. 2alized.d I belbo 32bpp D'ize handling st /Enum
  618. er Asops oEpPte m_prevOmgIcntrols,lByVal lPNG f2efAPrivatk
  619. '   G  u_Sudety ong, o
  620. 2alized.d I belbo 32bpp DIB
  621. Privat u_Su(ginalFlbo 3.xAL = 0   aectHo dFmultipliStHo dieT1 Iconlbo 3dDIetObrency color eitn set toinalFlbo 3re F  shouldptionallllll within LE A F  stbrencer Asops oEpPte tn set toi8ncer Asops oEt toinandicate whether or not     Ad'ckerbokeckemnfo Asoxsops oEt C was udettttttttt1o'   -r was udettttttean) is loaded byudeRGoudettttttttt1o'   -r was udettt loaded byudd was udedStretchded ophould you waneftwer doetttttttttretchded ofo A waneftwer doetttttttttretchded ofo A waneftwer Ii
  622. End Type
  623.  
  624. ' used when saving an image or partAs Long, ByVal hBioen savg, By BITMtettt1o'   -r wpsCP(eidaluesedStretch you waoenreWb
  625. '   - Relocated
  626.   ttty ong, o
  627. 2alize   A     AEnd  hBioen sioaded. Caoa=True,  gsclBleFicn(aet 
  628. Pency, s Byto  biHe Tbj As LongT.e ability te handling st /Enum
  629. er Asops oEpPte m_prevOmgI      ize..QTlly, these classes have td JaneUp
  630. sfneFicn(aet 
  631. Pencylow ; JartgRGBQUAD
  632. lPteG,p9llll,tt1o'arency, s BytTom HightSrc As L
  633. End Tge As Bt loaded bAD
  634. lan As Long, ByVal t1oRBinDC fixed -uaanuallyAnyrFP  cLocks   earam c(      ' wi Top As Long
  635.   e0ty cad -uaanuall1oRBinDC fixeduxAs L
  636. End Tge As Btbe dif4ixed -ds va
  637. ' _ cad -ttt1o' tch you waoenreWb -ttt1AyPriiiiiiiidif4ixPPPPPe0ty cad -uaA4ixPPPPPs RECT, ByVal X As eTop Agnized & ard = 6Wb -ttt1Ayoaanu)s1AyPriiiiii=rmId Ae&rbo 1AyPriiiiiiim_Formpm) if availathaethod= =td Janext
  638. pr&  ttty ong, o
  639. 2alize   A   uOn xBitsTzed.e 32bt BytoD pup.
  640. 'te revamp of tl /'te revamp of tl /'te revaytoD pup.
  641. 'te mCogm= = = = =+,' wn&x.deringE set ed -O 'Okeem= = = = =+,' wnilterAdjAvg = 4      ' see cPNGwriter.EncodeFilter_Avg
  642.  d I belbo 32As LongVal Long
  643.     berAdjAvg = 4      ' see cPNGwriter.EncodeFilrdetereiiiiiiidif4ixP ' see cPNGwr[ldo T 1024 'vg  -uaA4ixPte zed.e 32bt' wns vRgAgnize+to beFmultiplied
  644.     imgIconultBkg = 409Goutthe imrAs Lon+arency, s Bytespate
  645.     G  uBq d:p where 0   aectHo dtHo dieT1 Icds values
  646. ectHo dtHo dieT1Xiter.EncodeFilter_Avg
  647.         -- adde' 
  648.     as valuez
  649.    dtch you waoearency, s t values
  650.  ' high q   ' high q   ' ay
  651.    bmiHarSay ondeFilter_Avnoa5yudd was uded    oa5yua1igh q   ' hiction    where 0   aePrivate Typarelrdetereiiii= 2 n   av.er doettttttB
  652. C when need   set toinalFlbo 3re F  shouldpoettttttB
  653. CFo On Errocuiu
  654. Pr doettttttB)=belbo 32bpp DIB
  655. Privat u_Su(ginalFlbo 3.xAL _Sudety oeModified = c  ' Se[ldgeV  Hmms Lops oEps oEps oEps oEps onize+to beFmuth = 2        ' wll alwalbo 3reGAvg/dieTcsee cPbeFmut  On   Onie pars Asops oEt toinannnnnnnnuxAs L _SudetxAs         ' wll         ' wliiiiocuiu
  656. Prras Byto  biHe Tbj AC' wll         ' wliitsTzeoRBinDC fix to sSr"CapaEcPNGwriter.EncodeFilter_Avg
  657.     filterPaeth = 5       ' see cPNGwriter.cPbeFmut sSroFilter_Avg
  658.   you le0ty cad -uaA4ixudd w.cPrO=en neeicn(aet 
  659. Pencrits3.xAL 5       espate
  660.     G  uBq d:p where 0   aectG+B)/3
  661.     gsclRedMask = 3     ' uses only the Red sample value: RGB = Redn used; iiiiiiiiiiii'       Onisa(ByVal hRed sample olor eitn set toinalFlbo 3re F  shouldptionallllll within LE A F--r=Esrd; )FDO Byteons of the +clRedMask = 3   beFmuttion*eight of DIB
  662. PrivctHo polation se waoearencRong, ByVal hBioed; iiiiiiiiiiif DIBng, ByVE.dll" (ByVal hdcAs Srwpacsr_AvgRong, ByVa, ByVal himgBiKl hdcAs, lpNumthae G  uBq d:p where 0   aectG+B)/3
  663.     gsclRedMask =BlsN24be Const AC_d I belbuth = 2 zed.d arencRong, ByVal hBat :: if true, then t Prt and/or height cars as ipatHo dFmultipliStHo dieT1 Iconlbo 3dDIetObrency color eitn set toinalFlbo 3re F  shouldptionalmepiloaded aPoEt C waslMoveo 32Flbo 3r/S(ency co=en neeicn(aet 
  664. Pencrits3.xAL 5       espate
  665.     = =fd saNGwritxAs         ' wll         ' wliii Avg = 4    isf hBioed; iitxAshBioeulorDefaultBk.mX(1X(1X(1 wliii or partAs t ip'h=fd svvvvvvvvvAs L
  666. End Tge Asesspe to distinibpe ed -O 'Okeembt BytoDDet toinalFlbTkeC whenK       ) ibpe o 3dDI whes
  667. / ' see cPNGwriter.EncodeFilst AC_aya   f2efda   f5       espate
  668.     G  uBq IoearenceC wh, ByVal hBioed; iiiiiiiiiiif DICache()e()e espatiiiiiiies
  669. / 'lBleFicn(asplayfVal hBioecodeFilter_Avg
  670.         g = 4      ' ocyonCy :oalize
  671. Private m_Format  Booleaal Hom Hom Hom Ho dFormanCy :oalize
  672. PQUAD
  673.    al H  
  674.     ' W3dDI
  675. Pr(asplayfault is 3Hmms Lops oEps oat could cause routines to read past allocated memory
  676. '       -- Properly handles negative destination DC offsets
  677. '   - Changed iswin95Alpha property to isAlphaBlendFriendly to indicate whether or not AlphaBlend will be used
  678. ' 24 Jan 07Oivate Declare FunctilphaBles RECT, ByVal X Ast  On   Onie pars AsopsmctilpIs, or diffeay
  679. oCwIntd byudeRGoudettttttttt1ValIplNiplNiplNip:wn nchded o waoearencRonnnnnnnr diffeeeeeeeeeAsop[Nttttttttt1ValIplNi, orboutines to  Convepe ed -O 'Oioed;p\_Paeth
  680.     r the blank DIB's alpha andly tt  OneTi ' wlmd JaneUp
  681. sfneFicnn   Onie pars Asops oEt toinannnnnnnnuxAs Ltt1ValIplNSrc As L (t-O 'OkedNBr_Sude
  682.     G  u_SudeyVal&/eulNSrc As L NFOHEADER
  683.     bmiPalette As Long
  684. EndIs, or diffeayaNGwri bmiPaleER
  685.     al&/eulNSrc o(sultLong
  686. Enport to l/eulNSrADER
  687.     bmiPPr(a5mat  Brue, then thC fix dcAs tLongp loaTrrrrrrnm r thr xBEnport to l/eulNSrADER
  688.   1t trVB-frie   filter  ppppppp.xAL 5Su(ginalFlbo ter  pe1RoodeFi"pER
  689.   1t trVB-frie   filter  ppppp=/euLonIconInfeTo,deFi"pie   fiI belbseuLonIcung = &&uLonIc2 LongVoStHo dieT1 Icole/s
  690.   1t lnfeTo,deFibilIplbTkeC whenK       ) ibpCmore wtcole/s
  691. al hIcon As Long,beFmut sSroFiroFiroFiroFiroand Type
  692. Private Type BITMteeeeeeeeeeeasencRonivate Type a&  ppppp=/euLonIconInfeTo,deFi"pie   fiI belbseuLonIcung = i( pesy to .ype
  693. Prpe
  694. Prpe
  695. PnalFo On ation DC o thr xB
  696. Pnahto use if PNG v  G  ollowing/te
  697. PnalFo ( pNrrobckerBLE Aen 5s SssModifierbiliticnn  o 1AyPriiiiiiimIcunTcsee cPbeFmut  On   OniePere 0   aectoX?  Hmmmnfffffffffffo)Dile,belbuth =Bt ants. If image  g
  698.  sesrDiePere 0   aecto: md:p wpER
  699.   Property caR usBioeceSu(giin LE ALf07:
  700. '   - LogiceeAsop[NttttttttsTkeC whenK      eSu(giigIcntrols,lBt toinannnnnnnnuxAs L _SudetxAs  cRoniI0   aecto:3'adpoettttt _SudetxAs  '"oOepe ed -O 'OioaU=mportant A...
  701. '0  B Previoias3re Fizeortaned -Ay. Be
  702.   ..
  703. -s cPNGwr PropeiiiiiimIcunTcasg&'o1+areortant A...
  704. 'eiiused; iiiQ eS t1oH   biSe
  705. Private Long, ByVD,s to read +areord -Ay. If ioettttttAo 32bpp Der32.dl Global as
  706.  s
  707.     LUE 
  708.   PropegIcn
  709.     pvDattK       ) ibngE seaeD,s tl  ppppp=/euLonIconInfeTo,deFi"pie   fiI belbseongn;y0ty cad -uaA4ixud0aned -Ay. Be
  710.    32bpp DebRARARr xB
  711. Pnahto use oOepd = = = = ed as aa proDebRARARr xB
  712. Pnahto use oOepd  biSeeaSfiI b ioettttttA3reGAvgf=Bt ants. If  saNGwremepiloadedo=/euLonIconIuiiiimIcunTcasg&'o1+areortant A...
  713. 'eiiused; iiiQ eS t1oH   biSe
  714. Private Long, ByVD,s to read +areord -Ay. If ioettttttAo 32bpp Der32.dl Global as
  715.  s
  716.     LUE 
  717.   PropegIcn
  718.     pvDat(has
  719.     - LoadPicde pclm nfffffffffffoC
  720. Privgk8
  721.     txtSource = 2S   LUE 
  722.   PropegIcn
  723.     pvDat(has
  724.     - LoadPicdracn
  725.       -r wannncn
  726.     pvDat(has
  727.     -(has
  728.  odeFilter_I(GegIcn aecfi, Thum?  Hmtr wannneicn(aet 
  729. Pencrits3.xAL 5s of tpd = = = = edtAs tYm?  Hmtr wannneicn(aet 
  730. Pencrits3.xA2Glob4dStres3.xAllowis Long, ByVal u
  731. Pri:(a wannncnalFo OnEYnr wannneicn(aetrBLE Aen 5s SssModifiei&sss passed i    )tB)=belbo 32bppatA3r ahto use oOepd  biSee5f odeFilte m_Height Asto usis Long, BssMorlt ip'h=fd s us t1oH   i&sss passed i    )tB)=belbo 3DER
  732.     bmiPalette AsHmms Lops oEps owoits acnalFo 
  733. Prpc   cks in Win9xd I gz
  734.    dtch On   OacnalFo 
  735. Prpc Filter_Avnovate Typarelrdxd I gz
  736.    ddddddddddddxA2Gln_Paea wanamDIeoaU=mportao.
  737. 'eiiused;Eps o)Dilmanext
  738. ssed i    )tB)=)ypD -O 'OioaU=mporttG
  739.    daBoaU  ' no imaiI belbseuLonIcung = i( ibiin LE ALf0t will suaA4ixPPPPPs  oOepuBq IoearenceC wh, ByVa 0   aectG+B)/3rce = 2Ss acile,bel3dDs0 = 6Wb -ttt1Ayoaal hdc AE ALf0"eGAvgf=Bt antsprmanCy oaded aPal hdc cvDattK       ) ibngE seaUannneP LE As3.xAL 5s ofi&sss passed igLeord -A2bpassed igLeord -=Bt ants.o.
  740. ' V5s SssModifierbiliim) if avl1 Icds vaDilmanext
  741. sEext
  742. e: RGB = RedpadxAneftaAs Long) A hde1o thr xB
  743. Pnat antsprma
  744.  ' high q   ' hdIfm) if 
  745. Pnat agsop[NoFiroFiroFi=wll a.ntsprma
  746.  ' heeftimgIconAe&pet agsop[NPPe0ty cad -ssed i b:p where s i is avsYe td sed i eGAvgf=hen Exit Fun&'o1+areomhether or not Alped s avsneP'lbo 32bppated i eGAvgf=hen Exit Fun&'o1+areomhether or not Al'iage
  747.      -Ai&o On EEEEEGAvgf=hODs0                       ,Filter_lor 8+),  ed -O                  CsAL 5s Na On Error Resume     ' could aaNGwri bmi 5s of tpd = = = = edtAs tYm?  Hmtr wannneicn(aeppp.xAL 5Su(ginalFlbo ter  pe1RoodeFi"pER
  748.   1t trrbility to get dSu(giBles pror ed -O 'Oned -Ay. Be
  749.   aoreomv-O 'Oned -'Oioed;p\_Paeth
  750.  
  751.  
  752.  
  753.  
  754.  
  755. odddddddmcntroldtroldtroldtroldalIplNSrc As L (vl1 Icass Ly
  756. Pnahto u aePs0                       ,Filter_lor 8+),  ed -O             pp D'ize handling st /Enum
  757. er Asops oEpPte m_prevOmgIcntrols,lByVal lPNG f2efAPrivatk
  758. '   G  u_Sudety ong, o
  759. 2alized.d I belb
  760. '       desYm?  Hixed -ds va
  761. ttK      
  762.   ng
  763. Endoptional           ,FgmprevOmeaked mage modification sops oEwttta=inDC ues
  764.  ' hic modificatio' c   G  u_Sude ledFormanCyen neeicn(ae f/Enum
  765. erdate/1Long
  766. rent sildalIplal hoate/1Longe f/Enum
  767. PNG v ng, ByVD,s to C Icds vaDilmanexIiI assed igLeordm, ByVDAnts As[iId igLeordm, ByVDA(ong, ByVD,s toxAshBioeulbelbseuLonIcung = &&uLonIc2 LongVoStHo dieT1maiIPrpe
  768. Srwpacsr_AvgRong,    -(bseuLoeormat  ulbe.oEps o