imginfo.bas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. '-----------------------------------------------------------------------------
  2. ' Get Image info using DevIL
  3. ' DevIL Sample program using Powerbasic.
  4. '
  5. ' by Peter Scheutz, Scheutz & Clementsen Design
  6. ' Web: http://www.scheutz.dk
  7. ' e-mail: sourcecode@scheutz.dk
  8. '
  9. ' Last modified: 06/22/2002
  10. ' Based on DevIL Ver. 1.6.1 PB incs
  11. ' Filename: imgview.bas
  12. '
  13. ' Released under the GNU Lesser General Public License:
  14. ' http://www.gnu.org/copyleft/lesser.html
  15. '
  16. ' For information on use and download of DevIL goto: http://openil.sourceforge.net/
  17. ' (Get docs and "End User Package")
  18. '
  19. ' Report errors in the Powerbasic includes to e-mail above.
  20. '
  21. ' For general help on Powerbasic and DevIL, try the forums at:
  22. ' http://www.powerbasic.com
  23. '-----------------------------------------------------------------------------
  24. #Register None
  25. #Compile Exe "imginfo.exe"
  26. Option Explicit
  27. #Include "il.inc"
  28. #Include "ilu.inc"
  29. #Include "ilut.inc"
  30. Function OpenIL_TypeString(ByVal il_const As Dword) As String
  31. Select Case il_const
  32. Case %IL_BYTE : Function = "IL_BYTE"
  33. Case %IL_UNSIGNED_BYTE : Function = "IL_UNSIGNED_BYTE"
  34. Case %IL_SHORT : Function = "IL_SHORT"
  35. Case %IL_UNSIGNED_SHORT : Function = "IL_UNSIGNED_SHORT"
  36. Case %IL_INT : Function = "IL_INT"
  37. Case %IL_UNSIGNED_INT : Function = "IL_UNSIGNED_INT"
  38. Case %IL_FLOAT : Function = "IL_FLOAT"
  39. Case %GL_DOUBLE : Function = "GL_DOUBLE"
  40. Case Else : Function = "Type not defined"
  41. End Select
  42. End Function
  43. Function OpenIL_FormatString(ByVal il_const As Dword) As String
  44. Select Case il_const
  45. Case %IL_COLOUR_INDEX : Function = "IL_COLOUR_INDEX"
  46. Case %IL_COLOR_INDEX : Function = "IL_COLOR_INDEX"
  47. Case %IL_RGB : Function = "IL_RGB"
  48. Case %IL_RGBA : Function = "IL_RGBA"
  49. Case %IL_BGR : Function = "IL_BGR"
  50. Case %IL_BGRA : Function = "IL_BGRA"
  51. Case %IL_LUMINANCE : Function = "IL_LUMINANCE"
  52. Case Else : Function = "Format not defined"
  53. End Select
  54. End Function
  55. Function OpenIL_OriginString(ByVal il_const As Dword) As String
  56. ' Origin Definitions
  57. Select Case il_const
  58. Case %IL_ORIGIN_LOWER_LEFT : Function = "IL_ORIGIN_LOWER_LEFT"
  59. Case %IL_ORIGIN_UPPER_LEFT : Function = "IL_ORIGIN_UPPER_LEFT"
  60. Case Else : Function = "Origin type not defined"
  61. End Select
  62. End Function
  63. Function OpenIL_PalTypeString(ByVal il_const As Dword) As String
  64. ' Palette types
  65. Select Case il_const
  66. Case %IL_PAL_NONE : Function = "IL_PAL_NONE"
  67. Case %IL_PAL_RGB24 : Function = "IL_PAL_RGB24"
  68. Case %IL_PAL_RGB32 : Function = "IL_PAL_RGB32"
  69. Case %IL_PAL_RGBA32 : Function = "IL_PAL_RGBA32"
  70. Case %IL_PAL_BGR24 : Function = "IL_PAL_BGR24"
  71. Case %IL_PAL_BGR32 : Function = "IL_PAL_BGR32"
  72. Case %IL_PAL_BGRA32 : Function = "IL_PAL_BGRA32"
  73. Case Else : Function = "Pallete type not defined"
  74. End Select
  75. End Function
  76. Function PbMain() As Long
  77. Local ILErr As Dword
  78. Local info As ILinfo
  79. Local ID As Dword
  80. Local errString As Asciiz*1024
  81. If Len(Command$)=0 Then
  82. MsgBox "Usage: imginfo.exe filename"
  83. Exit Function
  84. End If
  85. ilInit
  86. ilGenImages ByVal 1, ID
  87. ILErr=ilGetError()
  88. If ILErr <> 0 Then
  89. errString = iluErrorString(ILErr)
  90. MsgBox "Error in ilGenImages" & $CRLF & errString
  91. Exit Function
  92. End If
  93. ilBindImage ID
  94. ILErr=ilGetError()
  95. If ILErr <> 0 Then
  96. errString = iluErrorString(ILErr)
  97. MsgBox "Error in ilBindImage" & $CRLF & errString
  98. GoTo done
  99. End If
  100. ' ilEnable %IL_FORMAT_SET
  101. ' ilEnable %IL_ORIGIN_SET
  102. ' ilEnable %IL_TYPE_SET
  103. '
  104. ' ilFormatFunc %IL_RGB
  105. ' ilOriginFunc %IL_ORIGIN_LOWER_LEFT
  106. ' ilTypeFunc %IL_UNSIGNED_BYTE
  107. '
  108. ' ilEnable %IL_CONV_PAL
  109. ' Do
  110. ' ILErr = ilGetError()
  111. ' Loop While (ILErr <> 0)
  112. ilLoadImage Command$
  113. ILErr=ilGetError()
  114. If ILErr <> 0 Then
  115. errString = iluErrorString(ILErr)
  116. MsgBox "Error in ilLoadImage" & $CRLF & errString
  117. GoTo done
  118. End If
  119. iluGetImageInfo info
  120. ILErr=ilGetError()
  121. If ILErr <> 0 Then
  122. errString = iluErrorString(ILErr)
  123. MsgBox "Error in iluGetImageInfo" & $CRLF & errString
  124. GoTo done
  125. Else
  126. MsgBox "DevIL Image info: " & $CRLF & $CRLF & _
  127. "Id: " & $TAB & $TAB & Format$(info.iId) & $CRLF & _
  128. "Data Pointer" & $TAB & Format$(info.iData) & $CRLF & _
  129. "Width: " & $TAB & $TAB & Format$(info.iWidth) & $CRLF & _
  130. "Height: " & $TAB & $TAB & Format$(info.iHeight) & $CRLF & _
  131. "Depth: " & $TAB & $TAB & Format$(info.iDepth) & $CRLF & _
  132. "Bpp: " & $TAB & $TAB & Format$(info.iBpp) & $CRLF & _
  133. "SizeOfData: " & $TAB & Format$(info.iSizeOfData) & $CRLF & _
  134. "Format: " & $TAB & $TAB & OpenIL_FormatString(info.iFormat) & $CRLF & _
  135. "Type: " & $TAB & $TAB & OpenIL_TypeString(info.iType) & $CRLF & _
  136. "Origin: " & $TAB & $TAB & OpenIL_OriginString(info.iOrigin) & $CRLF & _
  137. "PalType: " & $TAB & $TAB & OpenIL_PalTypeString(info.iPalType) & $CRLF & _
  138. "PalSize: " & $TAB & $TAB & Format$(info.iPalSize) & $CRLF & _
  139. "NumNext: " & $TAB & Format$(info.iNumNext) & $CRLF & _
  140. "NumMips: " & $TAB & Format$(info.iNumMips) & $CRLF & _
  141. "NumLayers: " & $TAB & Format$(info.iNumLayers)
  142. End If
  143. done:
  144. ilDeleteImages 1 , ID
  145. ' clear additional errors
  146. Do
  147. ILErr = ilGetError()
  148. Loop While (ILErr <> 0)
  149. End Function