December 03, 2020, 08:52:13 PM

Author Topic: [bb] Better WriteFile() and ReadFile() etc. by Streaksy [ 1+ years ago ]  (Read 642 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Better WriteFile() and ReadFile() etc.
Author : Streaksy
Posted : 1+ years ago

Description : This is great for handling large files.  Use it like you would the native file handling functions.  There are a few brand new ones chucked in aswell.

The reason it's faster (in theory), and in my opinion, neater, is that files are read and written in one go and the rest is done in memory, which is much faster.  When writing, the xCloseFile function is what dumps the preprepared data to the file.  When reading, the XReadFile function reads the whole file in one sweep and subsequent read-data functions just read the values from memory.  Using this method with large files when you're only reading a small part of the file is therefore probably inferior.

I'm pretty sure it's all in working order and the code should be accessible enough.  Hope it's useful.  =D
*** PUBLIC FUNCTIONS:

WRITING:
XWriteFile(filename$,encrypt=0,compress=0)
XWriteInt(filehandle,value)
XWriteByte(filehandle,value)
XWriteFloat(filehandle,value#)
XWriteString(filehandle,value$)
XWriteLine(filehandle,value$)
XWriteBytes(bank,filehandle,value,offset,count)
XWriteImage(filehandle,image)
XWriteTexture(filehandle,texture,write_alpha_channel)
XWriteBank(filehandle,bank)
READING:

XReadFile(filename$,encrypt=0,compress=0)
XReadInt(filehandle)
XReadByte(filehandle)
XReadFloat#(filehandle)
XReadString$(filehandle)
XReadLine$(filehandle)
XReadBytes(Bank,filehandle,value,offset,count)
XReadImage(filehandle)
XReadTexture(filehandle,Read_alpha_channel)
XReadBank(filehandle,Bank)
UNIVERSAL:
XCloseFile(filehandle)
XEof(filehandle)
*** TOKENS:

You can define tokens which are strings that will be stored in compressed files as a few bytes,  It is useful for common words etc. that needlessly take up space in files.  You can safely ignore this whole system if it makes no sense to you or just isn't that useful for your purposes.

XAddToken(string$)


Code :
Code: BlitzBasic
  1. Global XMashKey$="This is the encryption key.  Make it as long and as random and as varied as you can, but make sure you use the same key to load files with which they were saved."
  2.  
  3.  
  4.  
  5. Global xDefaultFileSize=1000    ;how big a bank is when first created by xWriteFile()
  6. Global bankstep=1500            ;how much is added to bank sizes when they get too small to contain the data (plus the size of the extra data)
  7. Global maxfilehandles=500
  8. Dim filehandle(maxfilehandles)
  9. Dim filebank(maxfilehandles)
  10. Dim filefn$(maxfilehandles)
  11. Dim FileSiz(maxfilehandles)
  12. Dim FileEnc(maxfilehandles)
  13. Dim FileCmp(maxfilehandles)
  14. Dim fileoffset(maxfilehandles)
  15. Dim Filetyp(maxfilehandles) ;1 for read, 2 for write, 0 for closed, 3 for random (but i cant be arsed coding random)
  16.  
  17. Global XTokenID$=Chr(255)               ;strings are tokenised when written to a file!
  18. Global xTokens,MaxxTokens=255   ;long/common words can be replaced with a token!  Use XAddToken(word$) To define them
  19. Dim xToken$(maxxTokens)
  20.  
  21.  
  22.  
  23.  
  24. ;DEMO
  25. pic=LoadImage("C:Blitz3DProjectsdexter's test.png")
  26. fil=xwritefile("moo.txt")
  27. xwriteimage fil,pic
  28. xclosefile fil
  29.  
  30. fil=xreadfile("moo.txt")
  31. pic2=xreadimage(fil)
  32. xclosefile fil
  33.  
  34. DrawImage pic2,0,0
  35. WaitKey:DeleteFile "moo.txt":End
  36.  
  37.  
  38.  
  39.  
  40. Function XSetKey(k$)
  41. XMashKey$=k
  42. End Function
  43.  
  44.  
  45. Function XReadFile(fn$,enc=0,cmp=0)
  46. sz=FileSize(fn)
  47. fil=ReadFile(fn)
  48. If fil=0 Then RuntimeError "Couldn't read from "+fn+"."
  49. For t=1 To maxfilehandles
  50. If filetyp(t)=0 Then
  51. filesiz(t)=sz ;for XEof() etc
  52. fileenc(t)=enc
  53. filecmp(t)=cmp
  54. fileoffset(t)=0
  55. filetyp(t)=1
  56. filebank(t)=CreateBank(sz)
  57. filefn(t)=fn
  58. ReadBytes filebank(t),fil,0,sz
  59. CloseFile fil
  60. If enc Then xmash filebank(t),sz
  61. If cmp Then xdecompress filebank(t),sz
  62. Return t
  63. EndIf
  64. Next
  65. RuntimeError "Too many files open!"
  66. End Function
  67.  
  68.  
  69. Function XWriteFile(fn$,enc=0,cmp=0)
  70. For t=1 To maxfilehandles
  71. If filetyp(t)=0 Then
  72. fileenc(t)=enc
  73. filecmp(t)=cmp
  74. fileoffset(t)=0
  75. filetyp(t)=2
  76. filebank(t)=CreateBank(xDefaultFileSize)
  77. filefn(t)=fn
  78. Return t
  79. EndIf
  80. Next
  81. RuntimeError "Too many files open!"
  82. End Function
  83.  
  84.  
  85.  
  86. Function XCloseFile(hnd)
  87. If filetyp(hnd)=2 Then                  ;closing a write handle, so write the whole lot then kill the bank
  88. If filecmp(hnd) Then xcompress filebank(hnd),filesiz(hnd):filesiz(hnd)=BankSize(filebank(hnd))
  89. If fileenc(hnd) Then xmash filebank(hnd),filesiz(hnd)
  90. fil=WriteFile(filefn(hnd)):If fil=0 Then RuntimeError "Couldn't write to "+filefn(hnd)+"."
  91. WriteBytes filebank(hnd),fil,0,filesiz(hnd)
  92. CloseFile fil
  93. FreeBank filebank(hnd)
  94. filetyp(hnd)=0
  95. EndIf
  96. If filetyp(hnd)=1 Then                  ;closing a read handle, so just kill the bank
  97. FreeBank filebank(hnd)
  98. filetyp(hnd)=0
  99. EndIf
  100. End Function
  101.  
  102.  
  103. Function XEof(hnd)
  104. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  105. If filetyp(hnd)=0 Then RuntimeError "Can't use closed file handle!"
  106. If FileTyp(hnd)<>1 Then RuntimeError "Can't check end-of-file for a file being written!"
  107. If fileoffset(hnd)=>FileSiz(hnd) Then Return True
  108. End Function
  109.  
  110.  
  111. Function XWriteInt(hnd,val)
  112. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  113. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  114. If filetyp(hnd)<>2 And filetyp(hnd)<>3 Then RuntimeError "Can't write to a non-writey file handle!"
  115. offset=fileoffset(hnd):bnk=filebank(hnd)
  116. If offset+4>filesiz(hnd) Then filesiz(hnd)=offset+4
  117. If BankSize(bnk)<filesiz(hnd) Then ResizeBank bnk,filesiz(hnd)+bankstep
  118. PokeInt(bnk,offset,val):fileoffset(hnd)=fileoffset(hnd)+4
  119. End Function
  120.  
  121.  
  122. Function XWriteFloat(hnd,val#)
  123. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  124. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  125. If filetyp(hnd)<>2 And filetyp(hnd)<>3 Then RuntimeError "Can't write to a non-writey file handle!"
  126. offset=fileoffset(hnd):bnk=filebank(hnd)
  127. If offset+4>filesiz(hnd) Then filesiz(hnd)=offset+4
  128. If BankSize(bnk)<filesiz(hnd) Then ResizeBank bnk,filesiz(hnd)+bankstep
  129. PokeFloat(bnk,offset,val):fileoffset(hnd)=fileoffset(hnd)+4
  130. End Function
  131.  
  132.  
  133. Function XWriteByte(hnd,val)
  134. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  135. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  136. If filetyp(hnd)<>2 And filetyp(hnd)<>3 Then RuntimeError "Can't write to a non-writey file handle!"
  137. offset=fileoffset(hnd)
  138. bnk=filebank(hnd)
  139. If offset+1>filesiz(hnd) Then filesiz(hnd)=offset+1
  140. If BankSize(bnk)<filesiz(hnd) Then ResizeBank bnk,filesiz(hnd)+bankstep
  141. PokeByte(bnk,offset,val)
  142. fileoffset(hnd)=fileoffset(hnd)+1
  143. End Function
  144.  
  145.  
  146. Function XWriteString(hnd,val$,tokenise=1)
  147. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  148. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  149. If filetyp(hnd)<>2 And filetyp(hnd)<>3 Then RuntimeError "Can't write to a non-writey file handle!"
  150. If tokenise Then If xtokens>0 Then val=xtokenise(val)
  151. XWriteInt hnd,Len(val)
  152. For t=1 To Len(val)
  153. XWriteByte hnd,Asc(Mid(val,t,1))
  154. Next
  155. End Function
  156.  
  157.  
  158. Function XWriteLine(hnd,val$,tokenise=1)
  159. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  160. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  161. If filetyp(hnd)<>2 And filetyp(hnd)<>3 Then RuntimeError "Can't write to a non-writey file handle!"
  162. If tokenise Then If xtokens>0 Then val=xtokenise(val)
  163. For t=1 To Len(val)
  164. XWriteByte hnd,Asc(Mid(val,t,1))
  165. Next
  166. XWriteByte hnd,13
  167. XWriteByte hnd,10
  168. End Function
  169.  
  170.  
  171. Function XWriteBytes(bnk2,hnd,ofs,cnt)
  172. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  173. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  174. If filetyp(hnd)<>2 And filetyp(hnd)<>3 Then RuntimeError "Can't write to a non-writey file handle!"
  175. offset=fileoffset(hnd)
  176. bnk=filebank(hnd)
  177. If offset+cnt>filesiz(hnd) Then filesiz(hnd)=offset+cnt
  178. If BankSize(bnk)<filesiz(hnd) Then ResizeBank bnk,filesiz(hnd)+bankstep
  179. CopyBank bnk2,ofs,bnk,offset,cnt
  180. fileoffset(hnd)=fileoffset(hnd)+cnt
  181. End Function
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188. Function XReadByte(hnd)
  189. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  190. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  191. If filetyp(hnd)<>1 And filetyp(hnd)<>3 Then RuntimeError "Can't read from a non-ready file handle!"
  192. val=PeekByte(filebank(hnd),fileoffset(hnd))
  193. fileoffset(hnd)=fileoffset(hnd)+1
  194. Return val
  195. End Function
  196.  
  197.  
  198. Function XReadInt(hnd)
  199. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  200. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  201. If filetyp(hnd)<>1 And filetyp(hnd)<>3 Then RuntimeError "Can't read from a non-ready file handle!"
  202. val=PeekInt(filebank(hnd),fileoffset(hnd))
  203. fileoffset(hnd)=fileoffset(hnd)+4
  204. Return val
  205. End Function
  206.  
  207.  
  208. Function XReadFloat#(hnd)
  209. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  210. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  211. If filetyp(hnd)<>1 And filetyp(hnd)<>3 Then RuntimeError "Can't read from a non-ready file handle!"
  212. val#=PeekFloat(filebank(hnd),fileoffset(hnd))
  213. fileoffset(hnd)=fileoffset(hnd)+4
  214. Return val
  215. End Function
  216.  
  217.  
  218. Function XReadString$(hnd,tokenise=0)
  219. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  220. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  221. If filetyp(hnd)<>1 And filetyp(hnd)<>3 Then RuntimeError "Can't read from a non-ready file handle!"
  222. ln=XReadInt(hnd)
  223. For p=1 To ln
  224. val$=val$+Chr(XReadByte(hnd))
  225. Next
  226. If tokenise Then If xtokens>0 Then val=xdetokenise(val)
  227. Return val
  228. End Function
  229.  
  230.  
  231. Function XReadLine$(hnd,tokenise=0)
  232. If xeof(hnd) Then Return ""
  233. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  234. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  235. If filetyp(hnd)<>1 And filetyp(hnd)<>3 Then RuntimeError "Can't read from a non-ready file handle!"
  236. For p=1 To 32000
  237. If fileoffset(hnd)=>filesiz(hnd) Then Return val$;val$=val+Chr(13)+Chr(10):nored=1;RuntimeError "ReadLine timeout - end of file reached and no 13,10!"
  238. If nored=0 Then val$=val$+Chr(XReadByte(hnd))
  239.         If Len(val)>2 Then
  240.         If Mid(val,p-1,1)=Chr(13) And Mid(val,p,1)=Chr(10) Then
  241.         val=Left(val,Len(val)-2)
  242.         If tokenise Then If xtokens>0 Then val=xdetokenise(val)
  243.         Return val
  244.         EndIf
  245.         EndIf
  246. Next
  247. RuntimeError "ReadLine timeout - no 13,10 found!"
  248. End Function
  249.  
  250.  
  251. Function XReadBytes(bnk2,hnd,ofs,cnt)
  252. If hnd=0 Or hnd>maxfilehandles Then RuntimeError "Invalid file handle."
  253. If filetyp(hnd)=0 Then RuntimeError "Can't use a closed handle file!"
  254. If filetyp(hnd)<>1 And filetyp(hnd)<>3 Then RuntimeError "Can't read from a non-ready file handle!"
  255. offset=fileoffset(hnd)
  256. bnk=filebank(hnd)
  257. CopyBank bnk,offset,bnk2,ofs,cnt
  258. fileoffset(hnd)=fileoffset(hnd)+cnt
  259. End Function
  260.  
  261.  
  262. Function XMash(bnk,sz)          ;for the reading/writing of encrypted files using mah xfile system... it gets called by XReadFile and XCloseFile
  263. lk=Len(mashkey):kat=1
  264. SeedRnd sz
  265. b3=Rand(0,255)
  266. For t=0 To sz-1
  267. b1=PeekByte(bnk,t)
  268. b3=b3+3:If b3>255 Then b3=b3-256
  269. tik=tik+1:If tik=12 Then tik=0:b3=b3+Rand(3,121):If b3>255 Then b3=b3-256
  270. b2=Asc(Mid(mashkey,kat,1)) Xor b3
  271. PokeByte bnk,t,b1 Xor b2
  272. kat=kat+1:If kat>lk Then kat=1
  273. Next
  274. End Function
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283. Function xCompress(bnk,szz,cmp=0) ;does some RLE on the pesky zeroes
  284. bnk2=CreateBank(szz*1.5)
  285. t=0:t2=0
  286. PokeByte bnk2,t2,cmp:t2=t2+1
  287. Repeat
  288. b=PeekByte(bnk,t):t=t+1
  289. .rec
  290. PokeByte bnk2,t2,b:t2=t2+1
  291. If b<=cmp Then
  292. If t=szz Then
  293. PokeByte bnk2,t2,b:Goto donec
  294. Else
  295.         cnt=1
  296.         For k=1 To 256
  297.         bb=PeekByte(bnk,t):t=t+1
  298.                 If bb=b And t=szz Then  ;end of bank, but last char was in the RLE chunk
  299.                 cnt=cnt+1;tot up that final char then write the count
  300.                 PokeByte bnk2,t2,cnt-1:t2=t2+1
  301.                 Goto donec
  302.                 EndIf
  303.         If bb<>b And t=szz Then ;end of bank, but last char wasnt in the RLE chunk
  304.         PokeByte bnk2,t2,cnt-1:t2=t2+1 ;write the count to conclude the RLE
  305.         PokeByte bnk2,t2,bb:t2=t2+1:If bb=<cmp Then PokeByte bnk2,t2,0:t2=t2+1 ;write the new byte, plus a 0 (+1) if it needs a RLE count
  306.         Goto donec
  307.         EndIf
  308.                 If bb=b Then    ;found another peice of the RLE chunk
  309.                 cnt=cnt+1;tot it up
  310.                 EndIf
  311.                 If bb<>b Then   ;past the RLE chunk
  312.                 PokeByte bnk2,t2,cnt-1:t2=t2+1 ;write how many it had found
  313.                 b=bb:Goto rec ;restart the byte check sequence on the new byte
  314.                 EndIf
  315.         If k=256 Then
  316.         PokeByte bnk2,t2,255:t2=t2+1
  317.         Goto donebatch
  318.         EndIf
  319.         Next
  320. .donebatch
  321. EndIf
  322. EndIf
  323. .donec
  324. Until t=szz
  325. ResizeBank bnk,t2:CopyBank bnk2,0,bnk,0,t2:FreeBank bnk2
  326. End Function
  327.  
  328.  
  329. Function xDecompress(bnk,szz)
  330. bnk2=CreateBank(szz*1.5)
  331. t=0:t2=0
  332. cmp=PeekByte(bnk,t2):t=t+1
  333. Repeat
  334. b=PeekByte(bnk,t):t=t+1
  335. PokeByte bnk2,t2,b:t2=t2+1:If t2+10>BankSize(bnk2) Then ResizeBank bnk2,BankSize(bnk2)+200
  336. If b=<cmp Then
  337. cnt=PeekByte(bnk,t):t=t+1
  338. For m=1 To cnt
  339. PokeByte bnk2,t2,b:t2=t2+1::If t2+10>BankSize(bnk2) Then ResizeBank bnk2,BankSize(bnk2)+200
  340. Next
  341. EndIf
  342. Until t=szz
  343. ResizeBank bnk,t2:CopyBank bnk2,0,bnk,0,t2:FreeBank bnk2
  344. End Function
  345.  
  346.  
  347. Function xTokenise$(t$)
  348. lll=Len(t)
  349. For tt=1 To xtokens
  350. If lll=>Len(xtoken(tt)) Then t=Replace(t,xtoken(tt),xtokenid+Chr(tt))
  351. Next
  352. Return t
  353. End Function
  354.  
  355. Function xDeTokenise$(t$)
  356. If Len(t)< Len(xtokenid)+1 Then Return t
  357. For tt=1 To xtokens
  358. t=Replace(t,xtokenid+Chr(tt),xtoken(tt))
  359. Next
  360. Return t
  361. End Function
  362.  
  363. Function XAddToken(t$)
  364. If Len(t)<(Len(xtokenid)+1) Then RuntimeError "Pointless token: "+t+" (it's so short that the token would be larger!)"
  365. If Len(t)=(Len(xtokenid)+1) Then RuntimeError "Pointless token: "+t+" (it's so short that the token would be the same size!)"
  366. If xtokens=>maxxtokens Then RuntimeError "Too many tokens: "+t
  367. xtokens=xtokens+1
  368. xtoken(xtokens)=t
  369. End Function
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387. Function XWriteImage(f,img)
  388. XWriteInt f,ImageWidth(img)
  389. XWriteInt f,ImageHeight(img)
  390. LockBuffer ImageBuffer(img)
  391. For x=0 To ImageWidth(img)-1
  392. For y=0 To ImageHeight(img)-1
  393. hue=ReadPixelFast(x,y,ImageBuffer(img))
  394. r=(hue And $00FF0000) Shr 16:XWriteByte f,r
  395. g=(hue And $0000FF00) Shr 8:XWriteByte f,g
  396. b=(hue And $000000FF):XWriteByte f,b
  397. Next
  398. Next
  399. UnlockBuffer ImageBuffer(img)
  400. End Function
  401.  
  402.  
  403. Function XWriteTexture(f,tex,Alphah=0)
  404. XWriteInt f,TextureWidth(tex)
  405. XWriteInt f,TextureHeight(tex)
  406. XWriteByte f,alphah
  407. LockBuffer TextureBuffer(tex)
  408. For x=0 To TextureWidth(tex)-1
  409. For y=0 To TextureHeight(tex)-1
  410. hue=ReadPixelFast(x,y,TextureBuffer(tex))
  411. r=(hue And $00FF0000) Shr 16:XWriteByte f,r
  412. g=(hue And $0000FF00) Shr 8:XWriteByte f,g
  413. b=(hue And $000000FF):XWriteByte f,b
  414. If alphah Then a=(hue And $FF000000) Shr 24:XWriteByte f,a
  415. Next
  416. Next
  417. UnlockBuffer TextureBuffer(tex)
  418. End Function
  419.  
  420.  
  421. Function XWriteBank(f,bnk)
  422. XWriteInt f,BankSize(bnk)
  423. XWriteBytes bnk,f,0,BankSize(bnk)
  424. End Function
  425.  
  426.  
  427.  
  428.  
  429. Function XReadTexture(f,flags=9)
  430. w=XReadInt(f)
  431. h=XReadInt(f)
  432. alphah=XReadByte(f)
  433. tex=CreateTexture(w,h,flags)
  434. LockBuffer TextureBuffer(tex)
  435. For x=0 To TextureWidth(tex)-1
  436. For y=0 To TextureHeight(tex)-1
  437. r=XReadByte(f)
  438. g=XReadByte(f)
  439. b=XReadByte(f)
  440. If alphah Then a=XReadByte(f)
  441. hue=R Shl 16 Or G Shl 8 Or B
  442. WritePixelFast x,y,hue,TextureBuffer(tex)
  443. Next
  444. Next
  445. UnlockBuffer TextureBuffer(tex)
  446. Return tex
  447. End Function
  448.  
  449.  
  450.  
  451. Function XReadImage(f,flags=9)
  452. w=XReadInt(f)
  453. h=XReadInt(f)
  454. img=CreateImage(w,h)
  455. LockBuffer ImageBuffer(img)
  456. For x=0 To ImageWidth(img)-1
  457. For y=0 To ImageHeight(img)-1
  458. r=XReadByte(f)
  459. g=XReadByte(f)
  460. b=XReadByte(f)
  461. hue=R Shl 16 Or G Shl 8 Or B
  462. WritePixelFast x,y,hue,ImageBuffer(img)
  463. Next
  464. Next
  465. UnlockBuffer ImageBuffer(img)
  466. Return img
  467. End Function
  468.  
  469. Function XReadBank(f)
  470. siz=XReadInt(f)
  471. bnk=CreateBank(siz)
  472. XReadBytes bnk,f,0,siz
  473. Return bnk
  474. End Function


Comments :


Streaksy(Posted 1+ years ago)

 Forgot to mention something and it won't let me edit my post for some reason...The encryption and compression are seperately optional.  You can have both, neither, or either one.  Just use the same options when loading that you used for saving.  Compression uses the mashkey$ which can be set any time with xSetKey.The compression technique is a simple RLE and won't ALWAYS be suitable, but for map files etc with a lot of empty data it should save a lot of space.  Either way compression and encryption slows it down a tad.


Doktor Zeus(Posted 1+ years ago)

 tried slipping this in as an include, but it keeps telling me that an image is missing on the second line of the WriteImage function. In fact it won't even run as a standalone. Am I doing something wrong here? Do I need a more current version of BB3D than v1.98?


_PJ_(Posted 1+ years ago)

 As postd above, the code auses this image file
Code: [Select]
pic=LoadImage("C:Blitz3DProjectsdexter's test.png")Make sure you change this path to your own valid image file.


Doktor Zeus(Posted 1+ years ago)

 Thanks. Big post, missed the most important bit. Hope I can work out how to get this working, as my own image-to-stream saving code is woefully inefficient! :(


Doktor Zeus(Posted 1+ years ago)

 Hm, Well, I got it working OK, but I'm finding odd results when I use compression to save a texture. For some weird reason I get three vertical red lines down the middle of the texture that actually pass behind parts of the image - at first I thought they were affecting the alpha map, then I remembered this was a bitmap and didn't have an alpha map. Furthermore, compression has practically no effect at all on the size of the file that is output, so there's little reason to turn it on anyway. Otherwise, it's a pretty neat package though I'll have to adapt it slightly to my own purposes I think, since I *do* want to read small chunks of a file.-Ash


Streaksy(Posted 1+ years ago)

 Yeh.. after using this a little more I've had strange results with RLE compression and I don't tend to bother with it anymore.  Since banks are used it won't take much adaptation to use a zlib dll...I'll leave this here 'cos the RLE is a small part of this code and I think people will still have a use for this.  The encryption is pretty good, I think. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal