imgconv.bas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. '-----------------------------------------------------------------------------
  2. ' Convert Image 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 "imgconv.exe"
  26. Option Explicit
  27. #Include "il.inc"
  28. #Include "ilu.inc"
  29. #Include "ilut.inc"
  30. $If Not %Def(%TRUE)
  31. %TRUE = 1
  32. %FALSE = 0
  33. #EndIf
  34. $If Not %Def(%MAX_PATH )
  35. %MAX_PATH = 260
  36. #EndIf
  37. %OVERWRITE = %False '%True
  38. Function PbMain() As Long
  39. Local ILErr As Dword
  40. Local info As ILinfo
  41. Local ID As Dword
  42. Local errString As Asciiz*1024
  43. Local Infile As Asciiz*%MAX_PATH
  44. Local Outfile As Asciiz*%MAX_PATH
  45. Infile="C:\test.bmp" ' OBS: Change this !
  46. Outfile="C:\test.tga" ' OBS: Change this !
  47. ilInit
  48. ilPushAttrib %IL_ALL_ATTRIB_BITS
  49. ILErr=ilGetError()
  50. If ILErr <> 0 Then
  51. errString = iluErrorString(ILErr)
  52. MsgBox "Error in ilPushAttrib" & $CRLF & errString
  53. Exit Function
  54. End If
  55. ilGenImages ByVal 1, ID
  56. ILErr=ilGetError()
  57. If ILErr <> 0 Then
  58. errString = iluErrorString(ILErr)
  59. MsgBox "Error in ilGenImages" & $CRLF & errString
  60. Exit Function
  61. End If
  62. ilBindImage ID
  63. ILErr=ilGetError()
  64. If ILErr <> 0 Then
  65. errString = iluErrorString(ILErr)
  66. MsgBox "Error in ilBindImage" & $CRLF & errString
  67. GoTo done
  68. End If
  69. ' ilEnable %IL_FORMAT_SET
  70. ' ilEnable %IL_ORIGIN_SET
  71. ' ilEnable %IL_TYPE_SET
  72. ' ilFormatFunc %IL_RGB
  73. ' ilOriginFunc %IL_ORIGIN_LOWER_LEFT
  74. ' ilTypeFunc %IL_UNSIGNED_BYTE
  75. '
  76. ' ilEnable %IL_CONV_PAL
  77. ' Do
  78. ' ILErr = ilGetError()
  79. ' If ILErr<>0 Then
  80. ' errString = iluErrorString(ILErr)
  81. ' MsgBox "Error in ..Func or ilEnable" & $CRLF & errString
  82. ' End If
  83. ' Loop While (ILErr <> 0)
  84. ilLoadImage infile
  85. ILErr=ilGetError()
  86. If ILErr <> 0 Then
  87. errString = iluErrorString(ILErr)
  88. MsgBox "Error in ilLoadImage" & $CRLF & errString
  89. GoTo done
  90. End If
  91. ' unrem to test these effects.
  92. ' iluRotate 50
  93. ' iluPixelize 5
  94. ' iluEnlargeImage 2,2,4
  95. ' iluBlurGaussian 4
  96. ' Do
  97. ' ILErr = ilGetError()
  98. ' If ILErr<>0 Then
  99. ' errString = iluErrorString(ILErr)
  100. ' MsgBox "Error in Effect" & $CRLF & errString
  101. ' End If
  102. ' Loop While (ILErr <> 0)
  103. If %OVERWRITE=%True And ilIsDisabled(%IL_FILE_OVERWRITE) Then
  104. ilEnable %IL_FILE_OVERWRITE
  105. ilSaveImage outfile
  106. 'ilDisable %IL_FILE_OVERWRITE ' done by ilPushAttrib/ilPopAttrib
  107. Else
  108. ilSaveImage outfile
  109. End If
  110. ILErr=ilGetError()
  111. If ILErr <> 0 Then
  112. errString = iluErrorString(ILErr)
  113. MsgBox "Error in ilSaveImage" & $CRLF & errString
  114. GoTo done
  115. Else
  116. MsgBox "Picture converted"
  117. End If
  118. done:
  119. ilDeleteImages 1 , ID
  120. ilPopAttrib
  121. ' clear additional errors
  122. Do
  123. ILErr = ilGetError()
  124. Loop While (ILErr <> 0)
  125. End Function